define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
    var types = JSON.parse($(':hidden[name=types]').val());
    // types = JSON.parse(types);

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'wx/amoy/index',
                    add_url: 'wx/amoy/add',
                    del_url: 'wx/amoy/del',
                    multi_url: 'wx/amoy/multi',
                    table: 'amoy',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'amoy_id',
                sortName: 'amoy_id',
                columns: [
                    [
                        // {checkbox: true},
                        {field: 'amoy_id', title: __('Amoy_id'), operate:false},
                        {field: 'amoy_sn', title: __('Amoy_sn')},
                        {field: 'nickname', title: __('Nickname')},
                        {field: 'tel', title: __('Mobile')},
                        {field: 'user_name', title: __('User_name')},
                        {field: 'full_name', title: __('Full_name'), operate: false},
                        {field: 'type_name', title: __('Type_name'),formatter: Table.api.formatter.status, searchList: types, style: 'min-width:100px;'},
                        {field: 'role', title: __('Role'),formatter: Table.api.formatter.status, searchList: {'1': '自发', '2': '代发'}, style: 'min-width:100px;'},
                        {field: 'add_time', title: __('Add_time'),formatter: Table.api.formatter.datetime, operate: 'BETWEEN', type: 'datetime', addclass: 'datetimepicker', data: 'data-date-format="YYYY-MM-DD"'},
                        {field: 'click_pay', title: __('Click_pay'), operate: false},
                        {field: 'click_num', title: __('Click_num'), operate: false},
                        {field: 'click_pay_times', title: __('Click_pay_times'), operate: false},
                        {field: 'see_pay', title: __('See_pay'), operate: false},
                        {field: 'see_pay_time', title: __('See_pay_time'), operate: false},
                        {field: 'cash_deposit', title: __('Cash_deposit'), operate: false},
                        // {field: 'cash_deposit_status', title: __('Cash_deposit_status'), operate: false},
                        {field: 'reward', title: __('Offer_reward'), searchList: __('Status'), style: 'min-width:100px;'},
                        {field: 'mission_status', title: __('Offer_reward_status'), operate: false},
                        {field: 'is_show', title: __('Is_show'),operate:false},
                        {field: 'content', title: __('Content')},
                        {field: 'operate', title: __('Operate'), width:150, table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,
                            buttons: [
                                {
                                    name:'url',
                                    text:'',
                                    icon: 'fa fa-anchor',
                                    classname: 'btn btn-info btn-xs btn-dialog',
                                    url: 'wx/amoy/mobile_url'
                                }
                            ]
                        }
                    ]
                ],
                showToggle: false,
                showColumns: false,
                search:false
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});